﻿using System;
using System.Collections.Generic;
using SinBiota.Model.Business.PersistenceServices.Interfaces;
using SinBiota.Model.Entities;
using SinBiota.Model.Persistence.Repositories.Interfaces;

namespace SinBiota.Model.Business.PersistenceServices.Implementation
{
    public class KeywordPersistenceServices : IKeywordPersistenceServices
    {
        private readonly IKeywordRepository _keywordRepository;

        public KeywordPersistenceServices(IKeywordRepository keywordRepository)
        {
            _keywordRepository = keywordRepository;
        }

        public Keyword FindById(int id)
        {
            return _keywordRepository.FindById(id);
        }

        public IList<Keyword> FindAll()
        {
            return _keywordRepository.FindAll();
        }

        public void Delete(Keyword keyword)
        {
            _keywordRepository.Delete(keyword);
        }

        public void DeleteById(int id)
        {
            Delete(FindById(id));
        }
        public void Save(Keyword keyword)
        {
            _keywordRepository.Save(keyword);
        }

        public void Update(Keyword keyword)
        {
            _keywordRepository.SaveOrUpdate(keyword);
        }

        public IList<Keyword> FindByNameLike(string name)
        {
            return _keywordRepository.FindByInffix(x => x.Name, name);
        }

        public Keyword FindByName(string name)
        {
            return _keywordRepository.FindByEqRestrictionUniqueResult(x => x.Name, name);
        }
    }
}